
template<class T>
class GLA_ConstantState {
public:
    T centroids[N_CENTROIDS];
};

template<class T>
class GLA_Cluster : public GLA
{
private:
    GLA_ConstantState& cs;
    T stat[N_CENTROIDS];
    unsigned count[N_CENTROIDS];

    T& getStat(const unsigned i) const { return stat[i]; }
    unsigned getCount(const unsigned i) const { return count[i]; }
    
public:
    GLA_Cluster(const GLA_ConstantState& c)
    {
        for (unsigned i = 0; i < N_CENTROIDS; ++i) {
            stat[i] = 0;
            n[i] = 0;
         }
         cs(c);
    }
    void addItem(const T& data)
    {
         unsigned index = 0;
         T dist = DIST_MAX;     
         for (unsigned i = 0; i < N_CENTROIDS; ++i) { 
             const T lDist = computeDist(lDist, cs.centroids[i]);
             if (lDist < dist) {
                 dist = lDist;
                 index = i;
             } 
             WRITE(stat[index], lDist, '+');
             WRITE(count[index], 1, '+');
         }
     }

     void addState(const GLA_Cluster& other)
     {
          for (unsigned i = 0; i < N_CENTROIDS; ++i) {
              stat[i] += other.getStat(i);
              count[i] += other.getCount(i);
          }
      }
};
